package com.chenhao.springcloud.chenhaodesignservice.pattern.creational.singleton;

import java.io.*;

/**
 * Description:
 *
 * @author chenhao
 * @date 2020/12/17 10:30
 */
public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
       /* LazySingleton lazySingleton = LazySingleton.getLazySingleton();
        System.out.println("program end");*/
    /*    Thread t1 = new Thread(new T());
        Thread t2 = new Thread(new T());
        t1.start();
        t2.start();
        System.out.println("end");*/
        HungrySingleton instance = HungrySingleton.getInstance();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("singleton_file"));
        oos.writeObject(instance);
        File file = new File("singleton_file");
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        HungrySingleton newInstance = (HungrySingleton) ois.readObject();

        System.out.println(instance);
        System.out.println(newInstance);
        System.out.println(instance==newInstance);
    }
}
